window.uam = window.uam || {};
uam.Utils = {
		
	/* ************************
	 * Request Codes 
	 * ***********************/
	requestCode : {
		UP_REGISTRATION : 101,
		UP_EDIT : 102,
		UP_VIEW : 103
	},
	
	/* ************************
	 * Response Codes 
	 * ***********************/
	responseCode : {
		OK : 200,
		ERROR : 500,
		// invalid request code
		ERROR_INVALID_REQUEST_CODE : 501,
		ERROR_INVALID_PARAMETERS : 502
	},
	
	/**
	 * ajax call to task
	 * 
	 * @param params:Object request parameter list
	 * @param succcess:Function handle the callback
	 * 
	 */
	callTask:function(params, success){
		
		if(typeof(microstrategy) != 'undefined'){
			var session = String(microstrategy.sessionState);
		}
		
		params = params || {};
		
		params["taskId"] = params["taskId"] || 'UserProfileService';
		params["taskEnv"] = params["taskEnv"] || 'xhr';
        params["taskContentType"] = params["taskContentType"] || 'json';
        params["session"] = params["session"] || String(session);
        
        success = success || function(data){ console ? console.log("callTask.data = " + data) : alert("callTask.data = " + data); }
		
        console.log(params);
        
		taskUrl = './taskProc';
		$.ajax({
			url:  taskUrl,
			type: 'GET',
			data: params,
			cache: "false",
			dataType: "text",
			async: true, //set to false in case we want it to wait
			success: success ,
			error: function (XMLHttpRequest, textStatus, errorThrown) {
		        alert("XMLHttpRequest="+XMLHttpRequest.responseText+"\ntextStatus="+textStatus+"\nerrorThrown="+errorThrown);
		    } 
		});
	}
};

var formValue = {
	Dashboard:"Dashboard",
	departmentId:"departmentId",
	departmentDesc:"departmentDesc",
	busnUCode:"busnUCode",
	busnUCodeDesc:"busnUCodeDesc",
	amexUCode:"amexUCode",
	amexUDesc:"amexUDesc",
	excpEndCode:"excpEndCode",
	radio:"detailAllAccess",
	phone:"1234567890",
	email:"test@gmail.com",
	firstname:"firstname",
	mIn:"mIn",
	lastname:"lastname",
	memail:"manager@gmail.com",
	VPName:"VPName",
	reason:"reason"
};

$(document).ready(function(){
	assignValue();
	/*$("#update").click(function(){
		validateAjax();
	});*/
});

function assignValue(){
	
	uam.Utils.callTask({'up_code':uam.Utils.requestCode.UP_VIEW}, function(data){
		console.log(data);
		eval("var responseData = " + data);
		
		
		if(responseData["status"] = uam.Utils.responseCode.OK){
			
			upData = responseData["data"];
			
			$("#select2").val(upData["Dashboard"]);
			$("#departmentId").val(upData["departmentId"]);
			$("#departmentDesc").val(upData["departmentDesc"]);
			$("#busnUCode").val(upData["busnUCode"]);
			$("#busnUCodeDesc").val(upData["busnUCodeDesc"]);
			$("#amexUCode").val(upData["amexUCode"]);
			$("#amexUDesc").val(upData["amexUDesc"]);
			$("#excpEndCode").val(upData["excpEndCode"]);
			$("#radio").val(upData["radio"]);
			$("#phone").val(upData["phone"]);
			$("#email").val(upData["email"]);
			$("#firstname").val(upData["firstname"]);
			$("#mIn").val(upData["mIn"]);
			$("#lastname").val(upData["lastname"]);
			$("#memail").val(upData["memail"]);
			$("#VPName").val(upData["VPName"]);
			$("#reason").val(upData["reason"]);
		}
	});
}

function validateAjax(){
	//ajax call to task
	if(typeof(microstrategy) != 'undefined'){
		var session = String(microstrategy.sessionState);
	}
	taskUrl = './taskProc';
	$.ajax({
		url:  taskUrl,
		type: 'GET',
		data:{
			taskId: 'UserProfileService',
			taskEnv: 'xhr',
			taskContentType:'json',
			session: String(session)
		},
		cache: "false",
		dataType: "text",
		async: true, //set to false in case we want it to wait
		success: function(data){
			console.log(data);
		} ,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
	        alert("XMLHttpRequest="+XMLHttpRequest.responseText+"\ntextStatus="+textStatus+"\nerrorThrown="+errorThrown);
	    } 
	});
}

